package org.spring.boot.func.proxy.init;

import org.spring.boot.func.annotation.EnableFuncLambda;
import org.spring.boot.func.type.EnableFuncLambdaType;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;
import java.util.Objects;

/**
 * @author Yiur
 */
public class FuncInitRegistry implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
        Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(EnableFuncLambda.class.getName());
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FuncInitBeanProxy.class);
        builder.addPropertyValue(EnableFuncLambdaType.PACKAGES.value, Objects.requireNonNull(annotationAttributes).get(EnableFuncLambdaType.VALUE.value));
        registry.registerBeanDefinition(FuncInitBeanProxy.class.getName(), builder.getBeanDefinition());
    }

}
